/**
 * Created by Administrator on 2016/7/4 0004.
 */
$(document).ready(function () {
    var list = $(".navigation-left-li");
    list.each(function (index) {
        if ($(this).css("color") == "rgb(0, 0, 0)") {
            page(index, list);
        }
    });
});

function page(num, list) {
    if (num <= 2) {
        customer_scroll(list);
    } else if (num >= 3 && num<6) {
        staff_scroll(list)
    }
}

function customer_scroll(list) {
    list.each(function (i) {
        $(this).click(function () {
            if (i == 0) {
                scroll_animate(0, $(this));
            } else if (i == 1) {
                scroll_animate(1100, $(this));
            } else if (i == 2) {
                scroll_animate(2400, $(this));
            }
        });
    });
    $(window).scroll(function () {
        if ($(window).scrollTop() < 200) {
            scroll_do(0, list);
        } else if ($(window).scrollTop() > 200 && $(window).scrollTop() < 1600) {
            scroll_do(1, list);
        } else if ($(window).scrollTop() > 1600) {
            scroll_do(2, list);
        }
    })
}

function staff_scroll(list) {
    list.each(function (i) {
        $(this).click(function () {
            if (i == 3) {
                scroll_animate(0, $(this));
            } else if (i == 4) {
                scroll_animate(1200, $(this));
            } else if (i == 5) {
                scroll_animate(2300, $(this));
            }
        });
    });
    $(window).scroll(function () {
        if ($(window).scrollTop() < 600) {
            scroll_do(3, list);
        } else if ($(window).scrollTop() > 600 && $(window).scrollTop() < 1600) {
            scroll_do(4, list);
        } else if ($(window).scrollTop() > 1600) {
            scroll_do(5, list);
        }
    })
}

function scroll_do(x, list) {
    list.each(function (index) {
        if (index == x) {
            $(this).css("color", "#000");
        } else {
            $(this).css("color", "#fff");
        }
    });
}

function scroll_animate(top, obj) {
    var i = $(window).scrollTop();
    var time = setInterval(function () {
        if (i < top) {
            i = i + 25;
            $(window).scrollTop(i);
            if (i >= top) {
                $(window).scrollTop(i);
                clearInterval(time);
            }
        } else if (i > top) {
            i = i - 25;
            $(window).scrollTop(i);
            if (i <= top) {
                $(window).scrollTop(i);
                clearInterval(time);
            }
        } else if (i == top) {
            clearInterval(time);
        }
    }, 5);
}